// ==UserScript==
// @name         VideoHelp
// @version      0.5.1
// @description  自己写的一个H5视频增强脚本,用于链工宝挂课
// @description  VideoHelp
// @author       bootloader
// @date         2020-12-18 16:59 周五
// @include      http://start.lgb360.com/video*
// @include      http://bingtuan.ouchn.cn/course/view*
// @grant        none
// @license      GPL
/**
 * 支持如下快捷键
 * left     后退10s
 * right    前进10s
 * up       增大音量
 * down     减小音量
 * pause    播放/暂停
 * 1        1倍播放速度
 * 2        2倍播放速度
 * 3        3倍播放速度
 * 4        4倍播放速度
 * 5        16倍播放速度
 * 
 * F        全屏/取消全屏
 * H        跳转到视频开始
 * E        跳转到视频结束
 * Z        正常播放速度
 * X        以0.5为变化量，降低播放速度(最小值1)
 * C        以0.5为变化量，增大播放速度(最大值20)
 * 
  */
// ==/UserScript==
(function() {
    "use strict";
    var skipTime = 10
    var skipVolume = 0.1
    var volumeTemp
    var playbackRateTemp
    function lgb360() {
        document.onkeydown = function (e) {
            var evt = e || window.event
            var v = document.querySelector('video')
            event.preventDefault()
            switch (evt.keyCode) {
                case 37: {
                    //left
                    if (v.currentTime < skipTime) {
                        v.currentTime = 0
                    }
                    v.currentTime = v.currentTime - skipTime
                    break
                }
                case 39: {
                    //right
                    if (v.currentTime > v.duration - skipTime) {
                        v.currentTime = v.duration
                    }
                    v.currentTime = v.currentTime + skipTime
                    break
                }
                case 38: {
                    //up
                    if (v.volume > 1 - skipVolume) {
                        v.volume = 1
                        break
                    }
                    v.volume = v.volume + 0.1
                    break
                }
                case 40: {
                    //down
                    if (v.volume < skipVolume) {
                        v.volume = 0
                        break
                    }
                    v.volume = v.volume - skipVolume
                    break
                }
                case 32: {
                    //pause
                    if (v.paused) {
                        v.play()
                    } else {
                        v.pause()
                    }
                    break
                }
                case 70: {
                    //fullscreen
                    if (!document.fullscreenElement) {
                        v.requestFullscreen()
                    } else {
                        if (document.exitFullscreen) {
                            document.exitFullscreen()
                        }
                    }
                    break
                }
                case 77: {
                    //muse
                    if (v.volume === 0) {
                        v.volume = volumeTemp
                    } else {
                        volumeTemp = v.volume
                        v.volume = 0
                    }
                    break
                }
                case 72: {
                    //h
                    v.currentTime = 0
                    break
                }
                case 69: {
                    //e
                    v.currentTime = v.duration
                    break
                }
                case 90: {
                    //z 正常播放速度
                    if (v.playbackRate == 1.0) {
                        if (playbackRateTemp >= 1.0) {
                            v.playbackRate = playbackRateTemp
                        } else {
                            playbackRateTemp = 1.0
                        }
                    } else {
                        v.playbackRate = 1.0
                    }
                    break
                }
                case 88: {
                    //x
                    if (v.playbackRate - 0.5 >= 1.0) {
                        v.playbackRate = v.playbackRate - 0.5
                    } else {
                        v.playbackRate = 1.0
                    }
                    playbackRateTemp = v.playbackRate
                    break
                }
                case 67: {
                    //c
                    if (v.playbackRate + 0.5 <= 20.0) {
                        v.playbackRate = v.playbackRate + 0.5
                    } else {
                        v.playbackRate = 20.0
                    }
                    playbackRateTemp = v.playbackRate
                    break
                }

                case 49: {
                    //1 1倍播放速度
                    v.playbackRate = 1.0
                    playbackRateTemp = v.playbackRate
                    break
                }
                case 50: {
                    //2 2倍播放速度
                    v.playbackRate = 2.0
                    playbackRateTemp = v.playbackRate
                    break
                }
                case 51: {
                    //3 3倍播放速度
                    v.playbackRate = 3.0
                    playbackRateTemp = v.playbackRate
                    break
                }
                case 52: {
                    //4 4倍播放速度
                    v.playbackRate = 4.0
                    playbackRateTemp = v.playbackRate
                    break
                }
                case 53: {
                    //5 16倍播放速度
                    v.playbackRate = 16.0
                    playbackRateTemp = v.playbackRate
                    break
                }
            }
        }
    }
    lgb360()
  })();
  